package com.chuji.crmcj.act;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.chuji.crmcj.R;
import com.chuji.crmcj.utils.UIUtils;

public class TryDriveExpressionActivity extends Activity {
    //试驾表现选择数据
    String [] expressForms={"非常满意","满意","一般"};
    //返回
    private ImageView mIv_back;
    //显示
    private ListView lv_car_color;
    //适配器
    CustomAdapter adapter;
    //请求码
    private int resultCode = 2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_try_drive_expression);
        //初始化组件
        mIv_back = (ImageView) findViewById(R.id.iv_back);
        lv_car_color = (ListView) findViewById(R.id.lv_car_color);
        //初始化适配器
        adapter=new CustomAdapter();
        //填充
        lv_car_color.setAdapter(adapter);
        lv_car_color.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //传值，返回数据
                Intent mIntent = new Intent();
                mIntent.putExtra("expression", expressForms[position]);
                // 设置结果，并进行传送
                setResult(resultCode, mIntent);
                finish();
            }
        });
        mIv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //传值，返回数据
                Intent mIntent = new Intent();
                mIntent.putExtra("expression", "未选择");
                // 设置结果，并进行传送
                setResult(resultCode, mIntent);
                finish();
            }
        });
    }
    //自定义适配器
    class CustomAdapter extends BaseAdapter {
        @Override
        public int getCount() {
            return expressForms.length;
        }

        @Override
        public Object getItem(int position) {
            return expressForms[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            /****1)根据list_item.xml--》得到当前子项元素的布局   【界面】*******/
            //b)声明ViewHolder
            ViewHolder viewHolder = null;
            //c)判断convertView是否为null
            if (convertView == null) {//第一次调用getView（）方法时为 null,意思就是在内存中没有
                viewHolder = new ViewHolder();
                convertView =  LayoutInflater.from(UIUtils.getContext()).inflate(R.layout.listview_car_color, null);
                //初始化组件
                viewHolder.tv_car_color = (TextView) convertView.findViewById(R.id.tv_car_color);
//                viewHolder.iv_apply_tag = (ImageView) convertView.findViewById(R.id.iv_apply_tag);
                convertView.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) convertView.getTag();
            }
            viewHolder.tv_car_color.setText(expressForms[position]);
//            if(loseApproveData.get(position).getState()==0){
//                viewHolder.iv_apply_tag.setVisibility(View.VISIBLE);
//            }else {
//                viewHolder.iv_apply_tag.setVisibility(View.GONE);
//            }
            return convertView;
        }
    }
    static class ViewHolder {
        private TextView tv_car_color;
    }
}
